package org.liveboardgames.agricola.business.action.processor;

import java.util.List;

import org.liveboardgames.agricola.domain.Change;
import org.liveboardgames.agricola.domain.Game;
import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.common.Target;
import org.liveboardgames.agricola.domain.player.Player;
import org.liveboardgames.agricola.model.enums.ChangesEnum;
import org.liveboardgames.agricola.model.structure.PopupModel;

public class ChooseBuildingMaterialActionProcessor extends ActionProcessor {

  public ChooseBuildingMaterialActionProcessor(Game game, Action action, List<Change> changes) {
    super(game, action, changes);
  }

  @Override
  public void execute() {
    Target target = action.getTarget();
    if (target instanceof Player) {
      // The number of resources that can be taken by the action
      int quantity = action.getOutputQuantity();

      // Update the model to tell it that the choose resource popup should be
      // displayed, along with the proper parameters
      Change popupChange = new Change(ChangesEnum.POPUP_ACTION_INDEX, PopupModel.POPUP_CHOOSE_RESOURCE_INDEX);
      Change popupResourcesChange = new Change(ChangesEnum.POPUP_NUMBER_OF_RESOURCES, quantity);

      changes.add(popupChange);
      changes.add(popupResourcesChange);
    }
  }

}
